<template>
    <div class="header" v-show="showHeader" :style="opacityStyle">
        <router-link tag="div" to="/" class="iconfont icon-back">&#xe624;</router-link>
        <div class="title">景点详情</div>
    </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showHeader: false,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      var top = document.documentElement.scrollTop
      if (top > 60) {
        this.showHeader = true
        var opacity = top / 160
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
      } else {
        this.showHeader = false
      }
    }
  },
  created () {
    window.addEventListener('scroll', this.handleScroll)
  },
  destroyed () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/variables.styl'
.header
    z-index 10
    position fixed
    top 0
    left 0
    right 0
    line-height .88rem
    background-color $bgColor
    text-align center
    .icon-back
        float left
        line-height .88rem
        margin-left .3rem
        font-weight bold
        font-size .34rem
        color #fff
    .title
        text-indent -1rem
        font-size .32rem
        color #fff
</style>
